﻿using UnityEngine;
using System.Collections;

public class Bird : MonoBehaviour
{

    public float timer = 0;

    public int frameNumber = 10;

    public int frameCount = 0;

    private bool isFly = false;
	// Use this for initialization
	void Start ()
	{
	  //  this.rigidbody.velocity = new Vector3(2.0f, 0, 0);
	}
	
	// Update is called once per frame
	void Update ()
	{
        if (GameManage._intance.gameState == GameManage.GAME_PLAY)
        {
            timer += Time.deltaTime;

            if (timer >= 1.0f/frameNumber)
            {
                frameCount ++;
                timer -= 1.0f/frameNumber;

                int frameIndex = frameCount%3;
                this.renderer.material.SetTextureOffset("_MainTex", new Vector2(frameIndex*0.3333f, 0));
            }
        }
        if (GameManage._intance.gameState == GameManage.GAME_PLAY)
	    {
	        if (Input.GetMouseButtonDown(0))
	        {
	            Vector3 vel = this.rigidbody.velocity;
	            this.rigidbody.velocity = new Vector3(vel.x, 5.0f, vel.z);
                AudioControl._intance.PlayAudio(AudioControl._intance.wing);
	        }
	    }

	}

    public void GetActive()
    {
        rigidbody.useGravity = true;
        rigidbody.velocity = new Vector3(2.0f, 0, 0);
    }
}
